using LANLauncher.Properties;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Forms;

namespace LANLauncher
{
	public class SplashScreen : Form
	{
        private IContainer components;

		private Label splashScreenMessage;

		private LANLauncher.Settings settings = new LANLauncher.Settings();

		public SplashScreen(string _message)
		{
			this.InitializeComponent();
			string str = "";
			str = "ENG";
			str = "ENG";
			this.settings.AddSetting("Language", str, null, null);
			this.settings.LoadFromFile();
			Setting setting = this.settings.GetSetting("Language");
			if (setting.Value == "English")
			{
				str = "ENG";
			}
			else if (setting.Value == "French")
			{
				str = "FRA";
			}
			else if (setting.Value == "Italian")
			{
				str = "ITA";
			}
			else if (setting.Value == "German")
			{
				str = "DEU";
			}
			else if (setting.Value == "Spanish")
			{
				str = "ESP";
			}
			else if (setting.Value == "Russian")
			{
				str = "RUS";
			}
            else if (setting.Value == "Hungarian")
            {
                str = "HUN";
            }
			StringLocaliser.language = str;
			this.splashScreenMessage.Text = StringLocaliser.LocaliseString(_message, false);
			base.TopMost = true;
			Thread thread = new Thread(() => {
				bool flag = true;
				while (flag)
				{
					Process[] processesByName = Process.GetProcessesByName("LANoire");
					if ((int)processesByName.Length < 1)
					{
						this.CloseSplashScreen();
						flag = false;
					}
					Process[] processArray = processesByName;
					for (int i = 0; i < (int)processArray.Length; i++)
					{
						if ((int)processArray[i].MainWindowHandle != 0)
						{
							this.CloseSplashScreen();
							flag = false;
						}
					}
					Thread.Sleep(50);
				}
			});
			thread.SetApartmentState(ApartmentState.STA);
			thread.Start();
		}

		private void CloseSplashScreen()
		{
			if (!base.InvokeRequired)
			{
				base.Close();
				return;
			}
			base.Invoke(new SplashScreen.CloseCallback(this.CloseSplashScreen));
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}

		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SplashScreen));
            this.splashScreenMessage = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // splashScreenMessage
            // 
            this.splashScreenMessage.AutoSize = true;
            this.splashScreenMessage.BackColor = System.Drawing.Color.Black;
            this.splashScreenMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.splashScreenMessage.ForeColor = System.Drawing.Color.White;
            this.splashScreenMessage.Location = new System.Drawing.Point(26, 262);
            this.splashScreenMessage.Name = "splashScreenMessage";
            this.splashScreenMessage.Size = new System.Drawing.Size(46, 17);
            this.splashScreenMessage.TabIndex = 1;
            this.splashScreenMessage.Text = "label1";
            // 
            // SplashScreen
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
            this.ClientSize = new System.Drawing.Size(560, 300);
            this.Controls.Add(this.splashScreenMessage);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Name = "SplashScreen";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "SplashScreen";
            this.Load += new System.EventHandler(this.SplashScreen_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

		}

        private delegate void CloseCallback();

        private void SplashScreen_Load(object sender, EventArgs e)
        {

        }
	}
}